﻿--[[
   @brief    main dialog contorl
   @author   hqzheng
   @version  1.0
   @date     2017-08-10
--]]


social_main_dialog_control = 
{
    nick_name = "";
    init = function()
        base_utility.log("talk_dialog init");
        ierd_tgp.tpf_ui.Require("social\\main_dialog\\view.lua");
        comm_center.listen_broadcast("i_brdcst_self_info_update", social_main_dialog_control.on_handle_self_info_update);
    end;

    open_social_panel = function(event_id, json_str)
        local social_state = comm_center.call_service("i_service_check_pwg_social_state", {});
        if nil ~= social_state and social_state.is_enabled then
            comm_center.call_service("i_service_show_pwg_social_window", { show = true });
            return;
        end
        local param_table = base_utility.json_to_table(json_str);
        if param_table ~= nil and param_table.show ~= nil then
           if 1 == param_table.show then
               social_main_dialog_view.last_panel_show_state = true;
               social_main_dialog_view.show(true);
           else
               social_main_dialog_view.last_panel_show_state = false;
               social_main_dialog_view.show(false);
           end
        end
    end;

    get_rc = function(input)
        return social_main_dialog_view:get_rc(); 
    end;

    is_social_panel_show = function(input)
        local is_show = social_main_dialog_view.is_show();
        ret = {};
        if is_show == TRUE then
            ret['is_show'] = 1;
        else
            ret['is_show'] = 0;
        end;
        return ret;
    end;

    refresh_social_friend_tab_reddot = function(data)        
        social_main_dialog_view.show_group_new_message_red_point_impl();
    end;

    refresh_social_group_tab_reddot = function(data)        
        social_main_dialog_view.show_group_new_message_red_point_impl();
    end;

    get_main_dialog_id = function (input)
        local data = {};
        data.main_dialog_id = social_main_dialog_view.root_id;
        return data;
    end;

    on_handle_self_info_update = function (data)
        if nil ~= data and nil ~= data.nick_name and "" ~= data.nick_name then
            social_main_dialog_control.nick_name = data.nick_name;
            social_main_dialog_view.set_title_name(data.nick_name);
        end
    end;
};

social_main_dialog_control.init();